package cn.smvc.sys.service.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.smvc.sys.dao.SysUserDao;
import cn.smvc.sys.dao.impl.SysUserDaoImpl;
import cn.smvc.sys.entity.SysUser;
import cn.smvc.sys.service.SysUserService;

@Service
public class SysUserServiceImpl implements SysUserService {
	
	private SysUserDao userDao = new SysUserDaoImpl();

	@Override
	public SysUser getUserByWechat(String wxName, String userName) {
		// TODO Auto-generated method stub
		SysUser user = null;
		StringBuilder sql = new StringBuilder();
		sql
		.append("select u.* from sys_user u              ")
		.append("join wechat_user wu on u.mobile=wu.tel  ")
		.append("where wu.toUserName=?                   ")
		.append("  and wu.fromUserName=?                 ")
		;
		try {
			List<SysUser> userList = userDao.findBySql(sql.toString(), wxName, userName);
			if(userList != null && userList.size() > 0) {
				user = userList.get(0);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return user;
	}

	@Override
	public SysUser get(String userId) {
		// TODO Auto-generated method stub
		SysUser user = null;
		try {
			user = userDao.findOne(userId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
	}

}
